package com.goods.business.controller;


import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author macro
 * @since 2021-11-08
 */
@RestController
@RequestMapping("/business/supplier")
public class BizSupplierController {

    @Autowired
    private SupplierService supplierService;

    @GetMapping("findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam Integer pageNum,
                                                             @RequestParam Integer pageSize,
                                                             @RequestParam(required = false) String name,
                                                             @RequestParam(required = false) String address,
                                                             @RequestParam(required = false) String contact) {
        PageVO<SupplierVO> supplierList = supplierService.findSupplierList(pageNum, pageSize, name, address, contact);
        return ResponseBean.success(supplierList);
    }

    /**
     * 添加分类
     */
    @PostMapping("add")
    public ResponseBean addSupplier(@RequestBody SupplierVO supplierVO) {
        supplierService.addSupplier(supplierVO);
        return ResponseBean.success();
    }

    @GetMapping("edit/{id}")
    public ResponseBean<SupplierVO> editCategory(@PathVariable Integer id) {
        SupplierVO supplierVO = supplierService.getSupplierById(id);
        return ResponseBean.success(supplierVO);
    }

    @PutMapping("update/{id}")
    public ResponseBean updateCategory(@PathVariable Integer id, @RequestBody SupplierVO supplierVO) {
        supplierService.updateSupplier(supplierVO);
        return ResponseBean.success();
    }

    @DeleteMapping("delete/{id}")
    public ResponseBean deleteSupplier(@PathVariable Integer id) {
        supplierService.deleteSupplier(id);
        return ResponseBean.success();
    }

    @GetMapping("findAll")
    public ResponseBean<List<SupplierVO>> findAll() {
        List<SupplierVO> supplierList = supplierService.findSupplierList();
        return ResponseBean.success(supplierList);
    }
}

